from app.databases import db_main


class User(db_main.Model):
    __bind_key__ = None  # 使用主数据库
    __tablename__ = 'sys_user'

    id = db_main.Column(db_main.Integer, primary_key=True)
    username = db_main.Column(db_main.String(80), unique=True, nullable=False)
    email = db_main.Column(db_main.String(120), unique=True, nullable=False)
    created_at = db_main.Column(db_main.DateTime, default=db_main.func.now())

    def to_dict(self):
        return {
            'id': self.id,
            'user_name':self.user_name,
            'email': self.email,
            'created_at': self.created_at.isoformat()
        }